import org.junit.Test;

import static org.junit.Assert.*;

public class ComplexTest1 {
        Complex a =new Complex(4,1);
        Complex b =new Complex(3,1);
        Complex c =new Complex(2,-1);

        /*获得虚部的Junit测试*/
        @Test
        public void getImagepart() {
            assertEquals("1.0",""+a.getImagepart());
            assertEquals("1.0",""+b.getImagepart());
            assertEquals("-1.0",   ""+ c.getImagepart());
        }

       /*获得实部的Junit测试*/
        @Test
        public void getRealpart() {
            assertEquals("4.0",""+a.getRealpart());
            assertEquals("3.0",""+b.getRealpart());
            assertEquals("2.0",""+c.getRealpart());
        }
        /*加法的Junit测试*/
        @Test
        public void addComplex() {
            assertEquals("7.0+2.0i",a.addComplex(b).toString());
            assertEquals("5.0i",b.addComplex(c).toString());
            assertEquals("6.0i",a.addComplex(c).toString());
        }
        /*减法的Junit测试*/
        @Test
        public void subComplex() {
            assertEquals("1.0i",a.subComplex(b).toString());
            assertEquals("-3.0i",c.subComplex(b).toString());
            assertEquals("2.0+2.0i",a.subComplex(c).toString());

        }
        /*乘法的Junit测试*/
        @Test
        public void mulComplex()
        {
            assertEquals("11.0+7.0i",a.mulComplex(b).toString());
            assertEquals("6.0i",b.mulComplex(c).toString());
            assertEquals("7.0i",a.mulComplex(c).toString());
        }
        /*除法的Junit测试*/
        @Test
        public void divComplex() {
            assertEquals("1.2i",a.divComplex(b).toString());
            assertEquals("1.0+1.0i",b.divComplex(c).toString());
            assertEquals("1.4+1.2i",a.divComplex(c).toString());
        }
    }
